package business_logic.game_elements;


import java.util.Collection;
import java.util.EnumSet;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import business_logic.GameElement;
import business_logic.Tile;
import business_logic.view.GameViewIdentifier;
import model.collisions.CollisionCategory;
import model.elements.NonPlayerCharacter;
import model.elements.ArtificialIntelligence.MovesRandomShootsRandom;
import model.elements.attributes.Coordinate2D;
import model.elements.attributes.Damage;
import model.elements.attributes.Lives;
import model.elements.attributes.Speed;
import model.elements.configurations.NonPlayerCharacterConfig;
import model.elements.states.weapon.BombEquipped;
import model.exceptions.ModelExceptions;

public final class LopezReggaeAlado extends NonPlayerCharacter implements GameElement
{
	private static final Collection<GameViewIdentifier> m_viewIdentifiers = 
            EnumSet.of(GameViewIdentifier.SPRITE_LOPEZ_REGGAE_ALADO);
    
    public LopezReggaeAlado(Coordinate2D startingPosition) throws ModelExceptions
    {
        super(startingPosition, new ConfigLopezRegaeAlado());
    }

    public Collection<GameViewIdentifier> getViewIdentifiers()
    {
        return m_viewIdentifiers;
    }

    @Override
    public void vivir()
    {    	
        try
        {
            this.update();
        }
        catch (ModelExceptions e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public int getX()
    {
        return Tile.pixelToTile( m_currentPosition.getRealX() );
    }

    @Override
    public int getY()
    {
        return Tile.pixelToTile( m_currentPosition.getRealY() );
    }

    private static final long m_serialVersionUID = 1L;
    
    @Override
    public Element save()
    {
        Element elem = DocumentHelper.createElement( this.getClass().getName() );
        elem.addAttribute( "serialVersion", m_serialVersionUID+"" );
        
        elem.addAttribute( "x", Math.floor( this.getPosition().getRealX() )+0.5 +"" );
        elem.addAttribute( "y", Math.floor( this.getPosition().getRealY() )+0.5 +"" );
        
        return elem;
    }
    
    public LopezReggaeAlado( Element elem ) throws ModelExceptions
    {
        super
        (
            new Coordinate2D
            (
                Double.parseDouble(elem.attributeValue("x")),
                Double.parseDouble(elem.attributeValue("y"))
            ),
            new ConfigLopezRegaeAlado()
        );
    }
}

class ConfigLopezRegaeAlado extends NonPlayerCharacterConfig
{
	private static final int 				LopezRegaeAladoHitPoints 		= 5;
	private static final double 			LopezRegaeAladoBaseSpeed 		= 0.002;
	private static final int 				LopezRegaeAladoContactDamage 	= 5;
	private static final CollisionCategory 	LopezRegaeAladoCollisionCategory = CollisionCategory.C_GHOST;
	
	public ConfigLopezRegaeAlado( ) {
		m_lives 		 = new Lives(LopezRegaeAladoHitPoints);
		m_speed 		 = new Speed(LopezRegaeAladoBaseSpeed);
		m_equippedWeapon = new BombEquipped(3);
		m_IA 			 = new MovesRandomShootsRandom( Tile.speedToTickets( LopezRegaeAladoBaseSpeed ) );
		m_damage 		 = new Damage(LopezRegaeAladoContactDamage);
		m_category 		 = LopezRegaeAladoCollisionCategory;
	}
}